<?php

/**
 * Description of class WebUser used to extend CWebUser and get more features.
 * @author breno
 */

class WebUser extends CWebUser {

    private $defaultRedirectView = 'atividade';

    /**
     * Return default view url.
     * @return string
     */
    public function getDefaultUrl() {
        return Yii::app()->homeUrl . $this->defaultRedirectView;
    }

    /**
     * Return first name.
     * @return string
     */
    public function getFirstName() {
        return ucfirst(strtok(Yii::app()->user->nomeCompleto, " "));
    }

    /**
     * Return full name.
     * @return string
     */
    public function getFullName() {
        return Yii::app()->user->nomeCompleto;
    }

    /**
     * This is a function that checks the field 'perfil'
     * in the User model (Usuario) to be equal to admin number or admin name set on WebUserTypes,
     * that means it's admin access it by Yii::app()->user->isAdmin()
     * @return bool
     */
    public function isAdmin() {
        return intval(Yii::app()->user->perfil) == WebUserTypes::AdminNumber
            || ucfirst(strtolower(Yii::app()->user->perfil)) == WebUserTypes::AdminName;
    }

    /**
     * This is a function that checks the field 'perfil'
     * in the User model (Usuario) to be equal to operator number or operator name set on WebUserTypes,
     * that means it's operator access it by Yii::app()->user->isOperator()
     * @return bool
     */
    public function isOperator() {
        return intval(Yii::app()->user->perfil) == WebUserTypes::OperatorNumber
            || ucfirst(strtolower(Yii::app()->user->perfil)) == WebUserTypes::OperatorName;
    }
    
    /**
     * This is a function that checks the field 'perfil'
     * in the User model (Usuario) to be equal to guest number or guest name set on WebUserTypes,
     * that means it's guest access it by Yii::app()->user->isGuest()
     * @return bool
     */
    public function isGuest() {
        return intval(Yii::app()->user->perfil) == WebUserTypes::GuestNumber
            || ucfirst(strtolower(Yii::app()->user->perfil)) == WebUserTypes::GuestName;
    }
}

